import path from "path";
import { defineConfig } from 'vite'

import uni from "@dcloudio/vite-plugin-uni";
import { UnifiedViteWeappTailwindcssPlugin as uvwt } from "weapp-tailwindcss/vite";
const { WeappTailwindcssDisabled } = require('./shared')

import AutoImport from 'unplugin-auto-import/vite'

// vite 插件配置
const vitePlugins = [uni(), uvwt({
  rem2rpx: true,
  disabled: WeappTailwindcssDisabled
})];


const resolve = (p) => {
  return path.resolve(__dirname, p);
};

const postcssPlugins = [
  require("autoprefixer")(),
  require("tailwindcss")({
    config: resolve("./tailwind.config.js"),
  }),
];

export default defineConfig({
  plugins: [
    vitePlugins,
    AutoImport({
      imports: [
        'vue',
        'uni-app',
        'pinia',
        {
          from: 'uni-mini-router',
          imports: ['createRouter', 'useRouter', 'useRoute']
        }
      ],
      dts: 'auto-imports.d.ts'
    }),
  ],
  css: {
    postcss: {
      // 内联写法
      plugins: postcssPlugins,
    },
  },
})